package model.fao;

import static org.junit.Assert.*;

import it.mrcrack.exception.DataFormatException;
import it.mrcrack.exception.DataNotFoundException;

import java.io.File;
import java.sql.SQLException;
import java.util.GregorianCalendar;
import java.util.List;

import model.bean.Report;
import model.dao.ReportsFileDAO;

import org.junit.Test;

import util.Costanti;

public class ReportsFAOTest {

	@Test
	public void testReportsFAOFile() {
		System.out.println("Testo ReportsFAO(File)");
		@SuppressWarnings("unused")
		ReportsFileDAO rf=null;
		try {
			rf=new ReportsFileDAO(new File(Costanti.PATH_DATAFILE));
		} catch (DataFormatException e) {
			assertEquals(e.getMessage(), "Il parametro passato non e' una directory");
		} catch (DataNotFoundException e) {
			fail(e.getMessage());
		}
		try {
			rf=new ReportsFileDAO(new File("a"+Costanti.DATAFILE));
		} catch (DataFormatException e) {
			fail(e.getMessage());
		} catch (DataNotFoundException e) {
			assertEquals(e.getMessage(), "Il file passato e' inesistente");
		}
		try {
			rf=new ReportsFileDAO(new File(Costanti.DATAMONITORFOLDER));
		} catch (DataFormatException e) {
			fail(e.getMessage());
		} catch (DataNotFoundException e) {
			fail(e.getMessage());
		}
	}

	@Test
	public void testReportsFAOString() {
		System.out.println("Testo ReportsFAO(String)");
		@SuppressWarnings("unused")
		ReportsFileDAO rf=null;
		try {
			rf=new ReportsFileDAO(Costanti.PATH_DATAFILE);
		} catch (DataFormatException e) {
			assertEquals(e.getMessage(), "Il parametro passato non e' una directory");
		} catch (DataNotFoundException e) {
			fail(e.getMessage());
		}
		try {
			rf=new ReportsFileDAO("a"+Costanti.DATAFILE);
		} catch (DataFormatException e) {
			fail(e.getMessage());
		} catch (DataNotFoundException e) {
			assertEquals(e.getMessage(), "Il file passato e' inesistente");
		}
		try {
			rf=new ReportsFileDAO(Costanti.DATAMONITORFOLDER);
		} catch (DataFormatException e) {
			fail(e.getMessage());
		} catch (DataNotFoundException e) {
			fail(e.getMessage());
		}
	}

	@Test
	public void testGet() {
		System.out.println("Testo get()");
		ReportsFileDAO rf=null;
		List<Report> lr=null;
		try {
			rf=new ReportsFileDAO(Costanti.DATAMONITORFOLDER);
			lr=rf.get();
		} catch (DataFormatException e) {
			e.printStackTrace();
		} catch (DataNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		for (Report report : lr) {
			System.out.println(report);
		}
	}
	@Test
	public void testGetGregorianCalendar() {
		System.out.println("Testo get(GregorianCalendar)");
		ReportsFileDAO rf=null;
		List<Report> lr=null;
		try {
			rf=new ReportsFileDAO(Costanti.DATAMONITORFOLDER);
			lr=rf.get(new GregorianCalendar(2011, 2, 21));
		} catch (DataFormatException e) {
			e.printStackTrace();
		} catch (DataNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		for (Report report : lr) {
			System.out.println(report);
		}
	}

	@Test
	public void testGetGregorianCalendarGregorianCalendar() {
		System.out.println("Testo get(GregorianCalendar)");
		ReportsFileDAO rf=null;
		List<Report> lr=null;
		try {
			rf=new ReportsFileDAO(Costanti.DATAMONITORFOLDER);
			lr=rf.get(new GregorianCalendar(2011, 2, 20), new GregorianCalendar(2011, 2, 25));
		} catch (DataFormatException e) {
			e.printStackTrace();
		} catch (DataNotFoundException e) {
			e.printStackTrace();
		} catch (SQLException e) {
			e.printStackTrace();
		}
		for (Report report : lr) {
			System.out.println(report);
		}
	}
}
